<!DOCTYPE html >
<html>
<head>
    <link rel="stylesheet" href="demos.css" type="text/css" media="screen" />
    
    <script src="../libraries/RGraph.common.core.js" ></script>
    <script src="../libraries/RGraph.common.key.js" ></script>
    <script src="../libraries/RGraph.bar.js" ></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <!--[if lt IE 9]><script src="../excanvas/excanvas.js"></script><![endif]-->
    
    <title>A stacked bar chart</title>

    <meta name="description" content="A demonstration of a stacked Bar chart. The chart uses the ondraw event to add some text to the chart" />
     
</head>
<body>
        
    <h1>A stacked bar chart</h1>
    
    <p>
        This is a stacked Bar chart. The labels that are inside the bars are achieved by using a DOM1 style ondraw event.
    </p>

    <canvas id="cvs" width="700" height="350">[No canvas support]</canvas>

    <script>
        $(document).ready(function ()
        {
            var canvas = document.getElementById("cvs");

            var bar = new RGraph.Bar({
                id: 'cvs',
                data: [[5.33,2.33,3.32],[3.42,2.23,4.23],[4.23,3.23,4.99], [7.99,2.98,2.35], [2.75,1.02,5.24]],
                options: {
                    grouping: 'stacked',
                    labels: {
                        self: ['John','James','Fred','Luke','Luis'],
                        above: {
                            self: true,
                            decimals: 2
                        }
                    },
                    linewidth: 2,
                    strokestyle: 'white',
                    colors: ['Gradient(#4572A7:#66f)','Gradient(#AA4643:white)','Gradient(#89A54E:white)'],
                    shadow: {
                        offsetx: 1,
                        offsety: 1,
                        blur: 10
                    },
                    hmargin: 25,
                    gutter: {
                        left: 45
                    },
                    background: {
                        grid: {
                            vlines: false,
                            border: false
                        }
                    },
                    key: {
                        self: ['Monday','Tuesday','Wednesday'],
                        colors: ['blue','#c00','#0c0'],
                        position: {
                            self: 'gutter',
                            x: canvas.width - 300,
                            y: 18,
                            gutter: {
                                boxed: true
                            }
                        }
                    },
                    axis: {
                        color: '#ccc'
                    },
                    noyaxis: true
                }
            }).on('draw', function (obj)
            {
                for (var i=0; i<obj.coords.length; ++i) {
                    obj.context.fillStyle = 'white';
                    RGraph.Text2(obj.context, {
                                               font:'Verdana',
                                               'size':10,
                                               'x':obj.coords[i][0] + (obj.coords[i][2] / 2),
                                               'y':obj.coords[i][1] + (obj.coords[i][3] / 2),
                                               'text':obj.data_arr[i].toString(),
                                               'valign':'center',
                                               'halign':'center'
                                              });
                }
            }).draw();
        })
    </script>


    <p>
        <a href="./">&laquo; Back</a>
    </p>

</body>
</html>